﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.OrmLite;
using ServiceStack;
using EquipmentManager.Dtos;

namespace EquipmentManager.Services
{
    class MyService: Service
    {

        public GetEquipmentsResponse Get(GetEquipments request)
        {
            List<Equipment> ress;
            if (request.Id != 0)
            {
                ress = new List<Equipment>();
                ress.Add(Db.SingleById<Equipment>(request.Id));
            }
            else
            {
                ress = Db.Select<Equipment>(request.Filter);
            }

            return new GetEquipmentsResponse { Entities = ress };
        }
        public PostEquipmentResponse Post(PostEquipment request)
        {
            Db.Save<Equipment>(request.Entity);
            return new PostEquipmentResponse { Id = request.Entity.Id };
        }
        public DeleteEquipmentResponse Delete(DeleteEquipment request)
        {
            Db.DeleteById<Equipment>(request.Id);
            return new DeleteEquipmentResponse();
        }
    }
}
